<?php
//生成批量修改的语句，需要支持多值


//$p['table']=$table;
//$p['update_item_name']    =array("mid","name","include_gene");
//$p['update_item_value']   =array("1","2","3");
//$p['condition_name']      = array("mid", "name", "include_gene");
//$p['condition_relation']  = array("=", ">", "<");
//$p['condition_value']     = array("'mid'", "'name'", "'include_gene'");
//$p['condition_condition'] = array("and", "and", "");
//$p['mode']="0";


//考虑到运算和数字对比。默认程序不加入单引号。请根据实际情况字符自动加入单引号。
//$p['condition_value']   = ["mid", "name", "include_gene"];


//$p['mode']="0";输入值则会返回过程


//本函数未能做到复杂的条件，只能做到 1 and 1 or 2  未在系统验证 1 or (2 and 3)。可以自行根据原理构建。


function update_datas($p)
{

//设置语句更新的表格
    $sql_prefix = "update ".$p['table']." SET ";



//设置要更新的项和值

    for($i=0;$i<count($p['update_item_name']);$i++)
    {

        $sql_middle=$p['update_item_name'][$i]." = '".$p['update_item_value'][$i]."',".$sql_middle;
    }


    $sql_middle=rtrim($sql_middle,",");



//设置要更新的条件

    for($i=0;$i<count($p['condition_name']);$i++)
    {

        $sql_suffix=$sql_suffix.$p['condition_name'][$i].' '.$p['condition_relation'][$i].$p['condition_value'][$i].' '.$p['condition_condition'][$i].' ';
    }



    $sql_suffix=" where ".$sql_suffix;



if($p['mode']=="1")
{
    echo $sqlstr=$sql_prefix.$sql_middle.$sql_suffix;
}

    return $sqlstr=$sql_prefix.$sql_middle.$sql_suffix;
}